home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / nt107.zip / KEYBOARD.DOC < prev    next >
Text File  |  1980-01-01  |  8KB  |  144 lines

  1.  
  2.  
  3.               ntekb:  nterm's Extended Keyboard handler
  4.               ======  =================================
  5.  
  6.                           Nevil Brownlee
  7.                Computer Centre,  University of Auckland
  8.  
  9.                           Mon 4 July 88
  10.  
  11.  
  12. For a long time now nterm users have asked me 'Why can't you map the PC's 
  13. numeric keyboard like a DEC one?' and 'Can't you do something which will make 
  14. the IBM Enhanced keyboard (with the function keys along the top) easier to use 
  15. with nterm?'
  16.  
  17. I didn't do this initially since it would have involved writing a keyboard 
  18. interrupt handler.  Instead I simply used the BIOS handler.  That provided 
  19. several advantages, i.e.
  20.  
  21.    -  It was simpler to write and debug (it's hard to use debug to look at 
  22.       a keyboard interrupt routine, since you don't have a keyboard for
  23.       DEBUG any more).
  24.  
  25.    -  It works on any machine which implements BIOS properly.
  26.  
  27.    -  It allows you to use memory-resident routines which 'hook' the
  28.       keyboard interrupts, e.g. mouse drivers and keyboard mappers.
  29.  
  30. The new handler is an attempt to provide key mappings which use the PC 
  31. keyboard better, without giving away the second two advantages.  Its design 
  32. aims were
  33.  
  34.    -  To continue using the BIOS key mappings wherever this was possible,
  35.       so as to allow earlier versions of the nterm Terminal Definition (.TDF)
  36.       files to be used unchanged.
  37.  
  38.    -  To provide new mappings for keys which BIOS doesn't (e.g. Sys Req on 
  39.       the AT, F11, F12, Enter etc. on the Enhanced keyboard).
  40.  
  41.    -  To provide a set of mappings allowing the numeric keypad to be used
  42.       as a DEC alternate keyboard, including the ability to implement 
  43.       Application Key and Cursor Key modes.
  44.  
  45.    -  To work properly with the original PC keyboard, the AT keyboard and the 
  46.       'Enhanced' keyboard, without requiring the user to specify which kind of 
  47.       keyboard is being used.
  48.  
  49.    -  To automatically determine whether the keyboard LEDs can be controlled
  50.       (i.e. whether we have an AT keyboard), and if possible set the keyboard 
  51.       LEDs to correctly indicate the shift status.
  52.  
  53. The handler is implemented in two parts; a set of routines in ntekb.asm which 
  54. does the actual interrupt handling, and a translate routine in ntntr.c which 
  55. translates the keyboard codes into nterm key codes.
  56.  
  57. When a keyboard interrupt is received the keyboard scan code is read.  If it 
  58. was a shift key the shift status is updated, the scan code and shift status 
  59. are placed in the nterm keyboard buffer, then the interrupt is passed on to 
  60. BIOS to be handled as usual.  The translate routine looks to see whether there 
  61. is a key code in nterm's keyboard buffer.  If there's also one in the BIOS 
  62. keyboard buffer the buffer is emptied and the BIOS scan code translations are 
  63. used.  This allows nterm to use the nterm keyboard buffer as a signal that a 
  64. key has been pressed, and then pick up all the characters placed in the BIOS 
  65. buffer by a 'hook' routine such as a mouse driver.  Note that the system 
  66. overhead in inspecting the nterm buffer pointers is considerably less than 
  67. that in using a BIOS interrupt to check the BIOS keyboard buffer.
  68.  
  69. Some key codes are not passed to BIOS; these are the ones which I believe to 
  70. be 'dangerous' to nterm.  For example the Print Screen key can ask BIOS to 
  71. dump the screen to a local printer - but if there isn't a printer I don't know 
  72. any way (except rebooting the system) to stop BIOS waiting indefinitly for the 
  73. printer to become ready!  Control-Num Lock stops BIOS dead, busy waiting for 
  74. another Control-Num Lock.  And so on.
  75.  
  76. To allow the 'DEC keypad' mapping I decided to use Num Lock to enter 'DEC 
  77. keypad' mode.  In this mode the Num Lock key (in the DEC keypad's PF2 
  78. position) maps to 'PF2', and therefore can't be used to leave this shift 
  79. state.  To return to normal you use Shift-Num Lock.  On the AT keyboard ntekb 
  80. sets the keyboard LEDs to indicate the shift status, and the 'shift key' codes 
  81. are not passed to BIOS.
  82.  
  83. To cope with the original PC keyboard, which has double-width Num Lock and 
  84. Scroll Lock keys as well as a triple-height Grey + key, ntekb maps Alt-Num 
  85. Lock, Alt-Scroll Lock and Alt-Grey + to key codes which can be used instead of 
  86. the AT Esc (left of Num Lock), Sys Req (right of Scroll Lock) and Grey * 
  87. (above Grey -).  This provides a usable alternate keypad; the only anomoly is 
  88. that the Grey - and + keys on the original PC keypad are thus 'upside down' 
  89. compared to where they are on the AT.
  90.  
  91. The PC keyboard also has the problem that it doesn't have keyboard LEDs.  
  92. Actually there is no problem if it really doesn't have LEDs, but many of them 
  93. do and those LEDs are just toggled by the Num Lock, Scroll Lock and Caps Lock 
  94. keys.  Since the toggling is done in the keyboard itself there's nothing nterm 
  95. can do to prevent it - instead I've implemented a 'display shift state' 
  96. option, which displays the shift status in the lower right-hand corner of the 
  97. screen.
  98.  
  99. The Enhanced keyboard has problems of its own; it does have extra keys, and 
  100. some of these send new scan codes which BIOS ignores.  Others send the same 
  101. scan codes as earlier keys, preceded by a code indicating that an 'enhanced' 
  102. key has been pressed.  ntekb sorts out this mess, and presents the translate 
  103. routine with enough information to map the key to its proper nterm key code.
  104.  
  105. nterm's key codes have been chosen so as to achieve the design aims stated 
  106. above.  To find out which scan code goes with which key you can either use 
  107. kpc's SHOW KEY command - which will tell you the code so you can SET KEY to 
  108. map it to something else - or you can look at the source code for ntvt.c, 
  109. which has a complete list of all the nterm key codes.
  110.  
  111. Compatibility with earlier versions of .TDF files provided some problems too.  
  112. To provide extra mappable keys for v200.tdf I had used Shifted numeric keypad 
  113. keys, but for ntekb these must simply produce the normal shifted key code.  
  114. One can't use Alt-numeric keypad keys, since BIOS uses these to form an input 
  115. decimal code, e.g. Alt-3,2 produces the ASCII character '2' when the Alt key 
  116. is released.  I therefore had to use Control-numeric keys for ntekb, so the 
  117. codes formerly produced by Shift-numeric keys are now produced by Control- 
  118. numerics, e.g. Control-End produces LF, etc.  One special case of this is that 
  119. Control-Print Screen must be pressed to get a printer screen dump.
  120.  
  121. Another compatibility issue is that when using an old version of .TDF file 
  122. such as v200.tdf, one will get a set of digits from the Shifted (or Num 
  123. Locked) numeric keypad keys.  This is achieved for the '0'..'9', '.', '+' and 
  124. '-' keys, which appear in their expected places.
  125.  
  126. One last piece of confusion:  when using vt.tdf, the Grey *, - and + keys 
  127. produce the characters *, - and + when they are unshifted.  But when they are 
  128. shifted they produce the DEC alternate keypad characters ',', '+' and 'Enter'!
  129.  
  130. Although all this sounds confusing, in practice it seems to work very well.  I 
  131. find it most convenient to leave the numeric keypad unshifted, so that the 
  132. arrow keys (which I use a lot) will move the cursor.  When I want an Alternate 
  133. Keypad key I have to hold down the shift key, but then I don't use these keys 
  134. nearly as much as I use the arrow keys.  The other unshifted keys map the DEC 
  135. editing, Help and Do keys; this also seems to work well.  Should I wish to 
  136. enter a lot of numeric data, Num Lock lets me do it.  Finally the function 
  137. keys; with a good Alternate Keypad mapping these don't get used very often at 
  138. all when working under VMS.  They can therefore either be ignored, or can be 
  139. mapped to user-chosen strings using SET KEY.
  140.  
  141. I would appreciate hearing any comments you may have about nterm's new 
  142. keyboard mapping.
  143.  
  144.